﻿using LuDragon.Web.Areas.Admin.Filters;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace LuDragon.Web.Areas.Admin.Controllers
{
    /// <summary>
    /// 公共控制器
    /// </summary>
    public class CommonController : BaseController
    {
        /// <summary>
        /// 上传文件
        /// 使用fromdata，支持多文件
        /// </summary>
        /// <returns></returns>
        //[HttpPost]
        //public JsonResult Upload()
        //{
        //    RequestResult<string> result = new RequestResult<string>();
        //    try
        //    {
        //        var files = Request.Files;
        //        var mapPath = Server.MapPath("/Upload");
        //        var dt = DateTime.Now;
        //        var filePath = "/" + dt.Year.ToString() + dt.Month.ToString() + "/" + dt.Day + "";
        //        if (!Directory.Exists(mapPath + filePath))
        //        {
        //            Directory.CreateDirectory(mapPath + filePath);
        //        }
        //        var index = 0;//防止文件名重复
        //        var allPath = "";
        //        foreach (var key in files)
        //        {
        //            index++;
        //            var fileName = dt.ToString("yyyyMMddhhmmss") + index;
        //            var fileNames = files[key.ToString()].FileName.Split('.');
        //            var exName = fileNames[fileNames.Length - 1];//扩展名
        //            var savePath = filePath + "/" + fileName + "." + exName;
        //            files[key.ToString()].SaveAs(mapPath + savePath);
        //            allPath += "/Upload" + savePath + ",";
        //        }
        //        result.Code = 200;
        //        result.Data = allPath.TrimEnd(',');
        //        result.Msg = "上传成功";
        //    }
        //    catch (Exception e)
        //    {
        //        result.Code = 500;
        //        result.Msg = e.Message;
        //        result.Data = null;
        //    }
        //    return Json(result, JsonRequestBehavior.DenyGet);
        //}


        [CheckLogin]
        public ActionResult Error(int code, string msg)
        {
            ViewBag.Code = code;
            ViewBag.Msg = msg;
            return View();
        }
    }
}